<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width">
	<title>Documentation Source: views/index.vue</title>

	<!--[if lt IE 9]>
	<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
	<![endif]-->
	<link type="text/css" rel="stylesheet" href="styles/sunlight.default.css">

	<link type="text/css" rel="stylesheet" href="styles/site.simplex.css">

</head>

<body>

<div class="navbar navbar-default navbar-fixed-top ">
<div class="container">
	<div class="navbar-header">
		<a class="navbar-brand" href="index.html">Documentation</a>
		<button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#topNavigation">
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
			<span class="icon-bar"></span>
        </button>
	</div>
	<div class="navbar-collapse collapse" id="topNavigation">
		<ul class="nav navbar-nav">
			
			<li class="dropdown">
				<a href="modules.list.html" class="dropdown-toggle" data-toggle="dropdown">Modules<b class="caret"></b></a>
				<ul class="dropdown-menu ">
					<li><a href="module-app.html">app</a></li><li><a href="module-article-card.html">article-card</a></li><li><a href="module-article-detail.html">article-detail</a></li><li><a href="module-article-item.html">article-item</a></li><li><a href="module-article-module.html">article-module</a></li><li><a href="module-back.html">back</a></li><li><a href="module-banner-module.html">banner-module</a></li><li><a href="module-bestseller-module.html">bestseller-module</a></li><li><a href="module-bestseller-product-card.html">bestseller-product-card</a></li><li><a href="module-detail-recommend-module.html">detail-recommend-module</a></li><li><a href="module-discovery.html">discovery</a></li><li><a href="module-grid-navs.html">grid-navs</a></li><li><a href="module-header.html">header</a></li><li><a href="module-index.html">index</a></li><li><a href="module-more-product-card.html">more-product-card</a></li><li><a href="module-navs-module.html">navs-module</a></li><li><a href="module-recommend-product.html">recommend-product</a></li><li><a href="module-recommend-product-module.html">recommend-product-module</a></li><li><a href="module-single-product.html">single-product</a></li><li><a href="module-single-product-module.html">single-product-module</a></li><li><a href="module-special-product.html">special-product</a></li><li><a href="module-special-product-module.html">special-product-module</a></li><li><a href="module-title.html">title</a></li><li><a href="module-views.html">views</a></li>
				</ul>
			</li>
			
			<li class="dropdown">
				<a href="global.html" class="dropdown-toggle" data-toggle="dropdown">Global<b class="caret"></b></a>
				<ul class="dropdown-menu ">
					<li><a href="global.html#$t">$t</a></li><li><a href="global.html#appHandle">appHandle</a></li><li><a href="global.html#axiosRequestReject">axiosRequestReject</a></li><li><a href="global.html#axiosRequestResolve">axiosRequestResolve</a></li><li><a href="global.html#axiosResponseReject">axiosResponseReject</a></li><li><a href="global.html#axiosResponseResolve">axiosResponseResolve</a></li><li><a href="global.html#conversionTime">conversionTime</a></li><li><a href="global.html#current_locale">current_locale</a></li><li><a href="global.html#delay">delay</a></li><li><a href="global.html#deleteEmptyValue">deleteEmptyValue</a></li><li><a href="global.html#formaturl">formaturl</a></li><li><a href="global.html#getCurrentDate">getCurrentDate</a></li><li><a href="global.html#getCurrentLocale">getCurrentLocale</a></li><li><a href="global.html#getHiddenProp">getHiddenProp</a></li><li><a href="global.html#getLanguage">getLanguage</a></li><li><a href="global.html#getLanguageForBackEnd">getLanguageForBackEnd</a></li><li><a href="global.html#getLanguageOptions">getLanguageOptions</a></li><li><a href="global.html#getUploadImage">getUploadImage</a></li><li><a href="global.html#getVisibilityChangeEventName">getVisibilityChangeEventName</a></li><li><a href="global.html#i18n">i18n</a></li><li><a href="global.html#imgPreLoad">imgPreLoad</a></li><li><a href="global.html#importStyle">importStyle</a></li><li><a href="global.html#isContained">isContained</a></li><li><a href="global.html#isHidden">isHidden</a></li><li><a href="global.html#loading_toast">loading_toast</a></li><li><a href="global.html#messages">messages</a></li><li><a href="global.html#parseLanguageParameter">parseLanguageParameter</a></li><li><a href="global.html#parseQueryString">parseQueryString</a></li><li><a href="global.html#resizeModal">resizeModal</a></li><li><a href="global.html#setLanguageOptions">setLanguageOptions</a></li><li><a href="global.html#setLocale">setLocale</a></li><li><a href="global.html#setMinHeightToInnerHeight">setMinHeightToInnerHeight</a></li><li><a href="global.html#startLoading">startLoading</a></li>
				</ul>
			</li>
			
		</ul>
        
            <div class="col-sm-3 col-md-3">
                <form class="navbar-form" role="search">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="Search" name="q" id="search-input">
                        <div class="input-group-btn">
                            <button class="btn btn-default" id="search-submit"><i class="glyphicon glyphicon-search"></i></button>
                        </div>
                    </div>
                </form>
            </div>
        
	</div>

</div>
</div>


<div class="container" id="toc-content">
<div class="row">

	
	<div class="col-md-12">
	
		<div id="main">
			

		<h1 class="page-title">Source: views/index.vue</h1>
    
<section>
    <article>
        <pre
            class="sunlight-highlight-javascript linenums">/*
 * 工程index
 * @Author: ljb
 * @Date: 2018-11-13 15:00:41
 * @Last Modified by: ljb
 * @Last Modified time: 2019-01-04 14:33:00
 */
&lt;style lang="less" rel="stylesheet/less" type="text/less" scoped>

	@import '~src/assets/css/common.less';

	.v-index {
		width: 100%;
		background-color: #F9F9F9;
	}
&lt;/style>
&lt;template>
	&lt;div class="v-index">

		&lt;!-- 区域模块组件 -->
		&lt;component
			v-for="app_module in app_home_setting"
			:key="app_module.layout_module_id"
			:is="block_map[app_module.code]"
			:code="app_module.code"
			:setting="app_module.setting"
			:layout-module-id="app_module.layout_module_id"
			@search="moduleSearch"
			@link="linkTo"/>

	&lt;/div>
&lt;/template>
&lt;script>

import * as API_LIST from 'src/API_LIST';

import qs from 'qs';
import { getLanguageForBackEnd } from 'src/i18n';

import banner from 'src/views/module/banner-module';
import navs from 'src/views/module/navs-module';
import singleProduct from 'src/views/module/single-product-module';
import specialProduct from 'src/views/module/special-product-module';
import recommendProduct from 'src/views/module/recommend-product-module';
import articleModule from 'src/views/module/article-module';
import bestseller from 'src/views/module/bestseller-module';

import { appHandle } from 'src/views/mixins/appHandle';
import { importStyle } from 'src/utils/dom-helper';

/**
 * 首页
 * @vue-data {Object} block_map 模块名称的映射表
 * @vue-data {string} current_lang 当前语言
 * @vue-data {array} app_home_setting 首页模块数组
 */
export default {
	components: {
		banner,
		navs,
		singleProduct,
		specialProduct,
		recommendProduct,
		articleModule,
		bestseller,
	},
	mixins: [appHandle],
	data() {
		return {
			block_map: {
				slideshow: 'banner',
				panx_app_icon_link: 'navs',
				latest: 'singleProduct',
				special: 'specialProduct',
				featured: 'recommendProduct',
				press_latest: 'articleModule',
				bestseller: 'bestseller',
			},	// 区域模块映射表

			current_lang: getLanguageForBackEnd(),	// 当前语言

			app_home_setting: [],		// 首页模块数组
		};
	},
	created() {
		this.fetchModule();
	},
	methods: {
		/**
		 * 从url读取模拟的主题
		 */
		readMockThemeName() {
			const query = qs.parse(window.location.search.replace(/^\?/, ''));
			return query.theme || 'default';
		},

		/**
		 * 产品专区模块跳转
		 * @param  {Object} [params={}] 需要传递的参数
		 */
		moduleSearch(params = {}) {
			const queryString = qs.stringify(params);
			const { origin, pathname } = window.location;
			const url = `${origin + pathname}#/more?${queryString}`;
			const jsonString = JSON.stringify({ url });
			this.handleApp('more', jsonString);
			// this.$router.push({ path: '/more', query: params });
		},
		/**
		 * 跳转链接
		 * @param  {string} href 链接地址
		 */
		linkTo(href) {
			let open_url;

			if (!href) return;

			if (this.isAppProtocol(href)) {
				const [app_fn, query_string] = href.split('://').pop().split('?');
				const params = qs.parse(query_string, { arrayFormat: 'indices' }) || {};
				this.handleApp(app_fn, JSON.stringify(params));
			} else if (this.isUrlProtocol(href)) {
				window.open(href);
			} else {
				open_url = `${window.location.protocol}//${href}`;
				window.open(open_url);
			}
		},

		/**
		 * 是否为正常网址协议（http/https）
		 * @param  {String} url 需要进行判断的url
		 * @return {Boolean} true代表是正常的网址，反之不是
		 */
		isUrlProtocol(url) {
			const protocol = url.split('://').shift();

			const valid_protocol = ['http', 'https'];

			return valid_protocol.indexOf(protocol) !== -1;
		},

		/**
		 * 是否为app自定义协议
		 * @param  {String} url {需要进行判断的url}
		 * @return {Boolean} true代表是app自定义协议，反之不是
		 */
		isAppProtocol(url) {
			const protocol = url.split('://').shift();

			const app_valid_protocol = ['app'];

			return app_valid_protocol.indexOf(protocol) !== -1;
		},

		/**
		 * 获取首页模块
		 * @return {promise} 请求模块的promise
		 */
		fetchModule() {
			const param = {
				language: this.current_lang,
				layout_route: 'app',
			};

			const query_str = qs.stringify(param);

			return this.$http.get(`${API_LIST.HOME_MODULE}?${query_str}`)
				.then(({ data }) => {
					if (data.code !== 0) throw new Error(data.error);

					this.app_home_setting = data.app_home_setting;

					importStyle(this.readMockThemeName());
				})
				.catch((err) => {
					const toast = this.$createToast({
						type: 'error',
						time: 2000,
						txt: err.message,
					});
					toast.show();
				});
		},
	},
};
&lt;/script>
</pre>
    </article>
</section>





		</div>
	</div>

	<div class="clearfix"></div>

	

</div>
</div>


    <div class="modal fade" id="searchResults">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title">Search results</h4>
          </div>
          <div class="modal-body"></div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div><!-- /.modal-content -->
      </div><!-- /.modal-dialog -->
    </div>


<footer>


<span class="jsdoc-message">
	Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a>
	
		on 2019-01-04T18:17:00+08:00
	
	using the <a href="https://github.com/docstrap/docstrap">DocStrap template</a>.
</span>
</footer>

<script src="scripts/docstrap.lib.js"></script>
<script src="scripts/toc.js"></script>

    <script type="text/javascript" src="scripts/fulltext-search-ui.js"></script>


<script>
$( function () {
	$( "[id*='$']" ).each( function () {
		var $this = $( this );

		$this.attr( "id", $this.attr( "id" ).replace( "$", "__" ) );
	} );

	$( ".tutorial-section pre, .readme-section pre, pre.prettyprint.source" ).each( function () {
		var $this = $( this );

		var example = $this.find( "code" );
		exampleText = example.html();
		var lang = /{@lang (.*?)}/.exec( exampleText );
		if ( lang && lang[1] ) {
			exampleText = exampleText.replace( lang[0], "" );
			example.html( exampleText );
			lang = lang[1];
		} else {
			var langClassMatch = example.parent()[0].className.match(/lang\-(\S+)/);
			lang = langClassMatch ? langClassMatch[1] : "javascript";
		}

		if ( lang ) {

			$this
			.addClass( "sunlight-highlight-" + lang )
			.addClass( "linenums" )
			.html( example.html() );

		}
	} );

	Sunlight.highlightAll( {
		lineNumbers : true,
		showMenu : true,
		enableDoclinks : true
	} );

	$.catchAnchorLinks( {
        navbarOffset: 10
	} );
	$( "#toc" ).toc( {
		anchorName  : function ( i, heading, prefix ) {
			return $( heading ).attr( "id" ) || ( prefix + i );
		},
		selectors   : "#toc-content h1,#toc-content h2,#toc-content h3,#toc-content h4",
		showAndHide : false,
		smoothScrolling: true
	} );

	$( "#main span[id^='toc']" ).addClass( "toc-shim" );
	$( '.dropdown-toggle' ).dropdown();

    $( "table" ).each( function () {
      var $this = $( this );
      $this.addClass('table');
    } );

} );
</script>



<!--Navigation and Symbol Display-->


<!--Google Analytics-->



    <script type="text/javascript">
        $(document).ready(function() {
            SearcherDisplay.init();
        });
    </script>


</body>
</html>
